<template>
  <div class="app-container customer-div">
    <el-menu :default-active="listQuery.tab" class="el-menu-demo" mode="horizontal" @select="handleSelect">
      <el-menu-item index="my">我的</el-menu-item>
      <el-menu-item index="all" v-if="logisticsSummaryAnalysisForAll">全部</el-menu-item>
    </el-menu>
    <div style="margin-top: 40px">
      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="100px">
        <el-form-item label="年份：">
          <el-date-picker
            :clearable="false"
            style="width:150px"
            v-model="listQuery.year"
            value-format="yyyy"
            type="year"
            placeholder="汇总年份">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="物流员："  v-if="listQuery.tab == 'all'">
          <el-select
            v-model="listQuery.freightUserId"
            filterable
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="item in userOptionList"
              :key="item.userId"
              :label="item.userName"
              :value="item.userId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
                  @click="handleSearchList()"
                  type="primary">
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--数据列表-->
    <div class="table-container">
      <el-table
              v-loading="listLoading"
              :data="tableData"
              border
              style="width: 100%; margin-top: 20px">
        <el-table-column
                align="center"
                label="合计项目"
                min-width="150">
          <template slot-scope="scope">
              {{scope.row.name}}
          </template>
        </el-table-column>
        <el-table-column
                align="center"
                label="1月"
                min-width="100">
          <template slot-scope="scope">
            {{scope.row.month1}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="2月"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.month2}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="3月"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.month3}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="4月"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.month4}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="5月"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.month5}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="6月"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.month6}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="7月"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.month7}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="8月"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.month8}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="9月"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.month9}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="10月"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.month10}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="11月"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.month11}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="12月"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.month12}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="合计"
          min-width="100">
          <template slot-scope="scope">
            {{scope.row.month13}}
          </template>
        </el-table-column>

      </el-table>
    </div>
  </div>
</template>
<script>
    import {freightSettlement,getOrderUsersList,logisticsReport} from '@/api/partner'
    import store from '@/store'
    import { mapGetters } from 'vuex'
    const defaultListQuery={
      pageNum: 1,
      pageSize: 10,
      year:'',
      tab:'my',
      freightUserId:''
    };



    export default {
      name: "index",
      data(){
          return {
              listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
              tableData: [],
              count: 0,
              listLoading: false,
              roles:store.getters.roles ? store.getters.roles : [],
              userOptionList:[]

          }
      },
      computed: {
        ...mapGetters([
          'name',
          'mobile',
          'userId'
        ]),
        logisticsSummaryAnalysisForAll(){
          if(this.roles.indexOf("logisticsSummaryAnalysisForAll") != -1){
            return true
          }else{
            return false
          }
        }
      },
      created() {
        let date = new Date()
        this.listQuery.year = date.getFullYear()+'';
        this.getList();
        this.getUserOptionList()
      },
      filters: {

      },

      methods:{
        //获取报价人下拉选项
        getUserOptionList() {
          getOrderUsersList({status:1,departmentId:4}).then((res) => {
            this.userOptionList = res;
          });
        },
        handleSelect(key){
          this.listQuery = JSON.parse(JSON.stringify(defaultListQuery))
          let date = new Date()
          this.listQuery.year = date.getFullYear()+'';
          this.listQuery.tab = key;
          this.handleSearchList();
        },

        handleSizeChange(val){
          this.listQuery.pageNum = 1;
          this.listQuery.pageSize = val;
          this.getList();
        },
        handleCurrentChange(val){
          this.listQuery.pageNum = val;
          this.getList();
        },

        handleSearchList(){
          this.listQuery.pageNum = 1;
          this.getList();
        },

        //获取订单列表
        getList() {
          this.listLoading = true;
          logisticsReport(this.listQuery).then(response => {
            this.tableData = response
            this.listLoading = false;
          }).catch(()=>{
            this.listLoading = false;
          });
        },

      },
    }
</script>

